// 引入场景
import { scene } from "./utils/init";
import * as THREE from 'three'

// 立方体基类的创建和使用
class BaseModel {
  constructor (scene) {
    // 颜色
    this.color = new THREE.Color(`rgb(
      ${Math.floor(Math.random() * 256)},
      ${Math.floor(Math.random() * 256)},
      ${Math.floor(Math.random() * 256)}  
    )`)
    // 位置
    this.position = [
      Math.floor(Math.random() * (10 - 1 + 1) +1),
      Math.floor(Math.random() * (10 - 1 + 1) +1),
      Math.floor(Math.random() * (10 - 1 + 1) +1)
    ]
    // 场景
    this.scene = scene
    // model
    this.model = null
  }
  randColor () {
    this.model.material.color = new THREE.Color(`rgb(
      ${Math.floor(Math.random() * 256)},
      ${Math.floor(Math.random() * 256)},
      ${Math.floor(Math.random() * 256)}  
    )`)
  }
}

// 子类
class MyCube extends BaseModel  {
  constructor(scene) {
    // 触发继承父类构造函数
    super(scene)
  }
}

const arr = []
for (let i = 0; i < 5; i++) {
  let cube = new MyCube(scene)
  arr.push(cube)
}
console.log(arr, 'arr');

// 双击 批量修改颜色和 首次旋转
window.addEventListener('dblclick', () => {
  arr.forEach(cube => {
    cube.randColor()
    cube.rotate()
  })
})